import request from '@/utils/request'

// 查询任务附件列表
export function listAttachment(query) {
  return request({
    url: '/task/attachment/list',
    method: 'get',
    params: query
  })
}

// 查询任务的附件列表
export function listAttachmentsByTask(taskId, taskType) {
  return request({
    url: `/task/attachment/listByTask/${taskId}/${taskType}`,
    method: 'get'
  })
}

// 查询任务附件详细
export function getAttachment(attachmentId) {
  return request({
    url: `/task/attachment/${attachmentId}`,
    method: 'get'
  })
}

// 上传任务附件
export function uploadAttachment(taskId, taskType, file) {
  const formData = new FormData()
  formData.append('taskId', taskId)
  formData.append('taskType', taskType)
  formData.append('file', file)
  
  return request({
    url: '/task/attachment/upload',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 下载任务附件
export function downloadAttachment(attachmentId) {
  return request({
    url: `/task/attachment/download/${attachmentId}`,
    method: 'get',
    responseType: 'blob',
    timeout: 60000
  })
}

// 删除任务附件
export function delAttachment(attachmentId) {
  return request({
    url: `/task/attachment/${attachmentId}`,
    method: 'delete'
  })
} 